Repository navigation
Conversation
The overall residual distribution (all_) in src/flac/analyze.c has a fixed array of FLAC__MAX_BLOCK_SIZE buckets, one per distinct residual value. A long enough file with enough distinct residuals wrote past the end of the array, corrupting the fields that follow it (or crashing). When the array is full, make the buckets twice as wide and merge the buckets that now overlap, as suggested in the issue. Files that fit keep exact, one-residual-per-bucket output. Add a test to test_flac.sh that analyzes a file with more distinct residuals than buckets and checks that every sample is counted. Fixes xiph#887
Author
|
Hi, no rush at all; whenever you have a moment, a review would be appreciated. This fixes the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #887
Problem
flac --analyze --residual-gnuplottracks a residual-value histogram inall_(src/flac/analyze.c) using a fixed array ofFLAC__MAX_BLOCK_SIZEbuckets, initially one per distinct residual. When an input contains more thanFLAC__MAX_BLOCK_SIZEdistinct residuals, writes go past the end of the bucket array, overwriting the adjacentpeak_indexandnbucketsfields and causing the crash reported by ASan in the issue.Fix
As suggested in the issue, coarsen the histogram when the bucket array fills: double the bucket width and merge buckets that now overlap. Output is unchanged for inputs that fit within the array, and the mean and standard deviation continue to be calculated from the exact residual values.
Testing
Built with ASan on Linux (gcc 13, CMake).
-0): before the change,--analyze --residual-gnuplotfails with an ASan SEGV inupdate_stats(analyze.c:207). After: exit 0, no ASan report.test/test_flac.sh: added a step that analyzes an 80000-sample file with more than 65535 distinct residuals and verifies that the overall distribution counts every sample. Before the fix, theflactest fails (counts 12359 samples instead of 80000). After: passes.ctest -R "generate_streams|flac": 2/2 pass.AI-assisted: drafted with an AI coding assistant; reproduced and tested locally before submitting.